home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 163_02 / swab.c < prev    next >
Text File  |  1988-01-30  |  640b  |  16 lines

  1. #include <errno.h>
  2. extern int abort();
  3. /*
  4. ** copy nbytes between from and to, swapping odd and even bytes in the process
  5. */
  6. swab(from, to, nbytes) char *from, *to; int nbytes; {
  7.   char temp;
  8.   if(nbytes & 1) abort(EINVAL); /* nbytes must be even */
  9.   nbytes >>= 1; /* get count in halfwords */
  10.   while(nbytes--) {
  11.     temp = *from++; /* temp allows copy to self */
  12.     *to++ = *from++;
  13.     *to++ = temp;
  14.     }
  15.   }
  16.